home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
batchut
/
echsys10.zip
/
ENV_SET.ASM
< prev
next >
Wrap
Assembly Source File
|
1989-09-25
|
28KB
|
721 lines
PAGE 60,132
;Usage is: call envsub ds:si -> length,string
; length is 1 byte long, <128
; if high bit on, primary environment is set.
; string is of form: name=value
; Copyright 1987, A. B. Krueger GPW MI 48236
; All rights reserved. Contact "ARNY KRUEGER"
; at the EXEC-PC BBS (414-964-5160) for permission
; to use commercially.
;
;Clone of SET command that demonstrates updating
; the environment string.
;If there is no secondary command processor, the
; global environment is updated
;If there is a secondary command processor, then
; its enviroment is updated
sb segment at 0 ;equates storage blocks and psp's
sb_kind db ' ' ;type of storage block: 'M' or 'Z'
sb_psp dw ? ;psp segment address
sb_length dw ? ;sb length in paragraphs
sb_head_length equ 10h ;length of sb header
org sb_head_length
sb_data db ? ;data in block
org 0h ;program segement prefix equates
psp_ret_int dw ? ;int 20h
org 2Ch
psp_env dw ? ;segment address of environment
org 50h
psp_dos_function dw ? ;address of function dispatcher
org 80h
psp_parm_string db ? ;1 byte length plus parm string
psp_length equ 100h
sb ends
cseg segment para public
assume cs:cseg,ds:cseg,es:sb
public env_set
;local data
cr equ 13
lf equ 10
sb_count dw 0 ;count of sb's encountered
sb_shell dw 0 ;segment address of shell sb
sb_shell_env dw 0 ;segment address of global env sb
sb_secondary dw 0 ;segment address of secondary command.com
sb_secondary_env dw 0 ;segment address of secondary command env
fatal_msg equ 80h
error_msg equ 40h
info_msg equ 20h
msg_flag db fatal_msg+error_msg ;+info_msg ;set flags
db 'Copyright 1987, A. B. Krueger GPW MI 48236'
secondary_msg db info_msg,'Secondary '
command_found db info_msg,'COMMAND.COM found',cr,lf,'$'
bad_dos_msg db fatal_msg,'Must be running under DOS 2.0 or above',cr,lf,'$'
bad_sb_msg db fatal_msg,'Bad storage block',cr,lf,'$'
bad_env_msg db error_msg,'Bad environment block',cr,lf,'$'
command_lost db error_msg,'Shell never found',cr,lf,'$'
addbadmsg db error_msg,'Environment corrupt',cr,lf,'$'
addmsg db info_msg,'Addition requested',cr,lf,'$'
removemsg db info_msg,'Removal requested',cr,lf,'$'
env_set_nospace db error_msg,'No space in environment string',cr,lf,'$'
env_set_syntax db error_msg,'Set string syntax error',cr,lf,'$'
type_string proc near ;type message at offset in dx
push ax ;save registers
push cx
push dx
push si
mov si,dx ;get message level
lodsb
and al,msg_flag ;compare to what sells
jz type_ret ;if not on list, send to bit bucket
mov dx,si
mov ax,0900h
int 21h
type_ret:
pop si
pop dx
pop cx
pop ax
ret
type_string endp
get_first_sb proc near ;get first storage block, point es at it
push ax
push bx
mov ax,5200h
int 21h ;es:bx points to memory block anchor+2
dec bx
dec bx
mov es,es:[bx] ;get first memory block address into es
pop bx
pop ax
ret
get_first_sb endp
get_next_sb proc near
push ax
mov ax,es ;get current paragraph
add ax,sb_length ;add in number of paragraphs
inc ax ;add 1 for header
mov es,ax ;set new extra segment address
pop ax
ret
get_next_sb endp
find_secondary_env proc near ;find env sb's for current program sb
push ax ;pointed to by es
push es
mov ax,es ;get address of secondary cp's sb
inc ax ;get its psp address
find_secondary_env_loop:
call get_next_sb ;get next sb
cmp ax,sb_psp ;match secondary's psp?
jne find_secondary_env_next ;if not, skip
mov sb_secondary_env,es ;otherwise, save
jmp find_secondary_env_exit ;and check no further
;lest we trash a .BAT block
find_secondary_env_next:
cmp sb_kind,'Z' ;last block?
jne find_secondary_env_loop
find_secondary_env_exit:
pop es
pop ax
ret
find_secondary_env endp
command_test proc near ;test program storage block at es:0
push ax
push bx
push cx
push dx
push ds
push es
push si
cmp sb_count,2
ja command_second
mov dx,offset command_found
call type_string
mov sb_shell,es
jmp command_test_good
command_second:
cmp sb_shell,0 ;did we find shell?
je command_first_bad ;if not, error
cmp word ptr es:psp_env+sb_head_length,0 ;check environment of program
je command_test_good ;if no environment, quit
push sb_shell
pop ds ;ds points to shell
mov al,byte ptr es:sb_head_length+psp_length
cmp al,0E9h ;a JMP?
jne command_test_good ;if not, no harm done
cmp al,byte ptr ds:sb_head_length+psp_length ;check 1st instruction
jne command_first_bad
mov si,sb_head_length+psp_length
mov di,sb_head_length+psp_length
mov cx,10 ;look at 10 words of code
repz cmpsw
clc
jcxz command_test_found ;if they all match, fine
jmp command_test_good ;if not, no harm done
command_test_found:
push cs
pop ds
mov sb_secondary,es
mov ax,es:psp_env+sb_head_length ;get env address
dec ax ;back up over sb header
mov sb_secondary_env,ax ;and save it
call find_secondary_env ;look for other env's
mov dx,offset secondary_msg
call type_string
jmp command_test_good
command_first_bad:
mov dx,offset command_lost
call type_string
stc
jmp c